// hdu5955
// 题意：
//
// 题解：
//
// 如果设概率的话可以假设经过第i个点的概率，然后根据ac自动机构出来的图
// 建立方程高斯消元。（也可以用终态结点的概率和为1替换任意方程）。
// 也可以假设经过第i个点的期望，来列方程，效果一样。
//
// ml:run = $bin < input
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

int const maxn = 20;
double const eps = 1e-8;
int da[maxn][maxn];
int inputid[maxn];
double a[1000][1000];
int n, l;

template <class T>
T abs(T x) { return x < 0 ? -x : x; }

namespace ac
{
    int const max_size = 1000;

    int next[max_size][20];
    int fail[max_size];
    int word_tail[max_size];

    template <int alpha>
    struct trie
    {
        trie() { reset(); }
        void reset() { alloc = 0; root = allocator(); }
        int size() const { return alloc; }

        void insert(int a[], int len, int id)
        {
            int now = root;
            for (int i = 0; i < len; now = next[now][a[i++]])
                if (next[now][a[i]] == -1)
                    next[now][a[i]] = allocator();
            word_tail[now]++;
            inputid[id] = now;
        }

        void make_ac_automaton()
        {
            std::queue<int> q;
            fail[root] = root;

            for (int ch = 0; ch < alpha; ch++)
                if (next[root][ch] == -1)
                    next[root][ch] = root;
                else {
                    fail[next[root][ch]] = root;
                    q.push(next[root][ch]);
                }

            while (!q.empty()) {
                int now = q.front(); q.pop();
                for (int ch = 0; ch < alpha; ch++)
                    if (next[now][ch] == -1)
                        next[now][ch] = next[fail[now]][ch];
                    else {
                        fail[next[now][ch]] = next[fail[now]][ch];
                        q.push(next[now][ch]);
                    }
            }
        }

    private:

        int allocator()
        {
            for (int i = 0; i < alpha; i++)
                next[alloc][i] = -1;
            word_tail[alloc] = 0;
            return alloc++;
        }

        int alloc;
        int root;
    };

}

ac::trie<6> aca;

void init_matrix(int n)
{
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) a[i][i] = -1;
    a[0][n] = -1;
    for (int i = 0; i < n; i++) {
        if (ac::word_tail[i]) continue;
        for (int j = 0; j < 6; j++) {
            int now = i;
            while (ac::next[now][j] == -1) now = ac::fail[now];
            now = ac::next[now][j];
            a[now][i] += 1.0 / 6.0;
        }
    }
    /* for (int i = 0; i <= n; i++) a[0][i] = 0; a[0][n] = -1; a[0][0] = -1; */

    // all end pos's probability sum to equal 1
    /* for (int i = 0; i <= n; i++) a[0][i] = 0; for (int i = 0; i < ::n; i++) a[0][inputid[i]] = 1; a[0][n] = 1; */
}

bool gauss(int n)
{
    for (int i = 0; i < n; i++) {
        int id = i;
        for (int j = i + 1; j < n; j++)
            if (abs(a[j][i]) > abs(a[id][i])) id = j;

        if (abs(a[id][i]) <= eps) return false;
        if (id != i)
            for (int j = i; j <= n; j++)
                std::swap(a[i][j], a[id][j]);

        for (int j = 0; j < n; j++)
            if (i != j) {
                double tmp = a[j][i] / a[i][i];
                for (int k = n; k >= i; k--)
                    a[j][k] -= a[i][k] * tmp;
            }
    }

    for (int i = n - 1; i >= 0; i--) {
        for (int j = i + 1; j < n; j++)
            a[i][n] -= a[j][n] * a[i][j];
        a[i][n] /= a[i][i];
    }
    return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int T; std::cin >> T;
    while (T--) {
        std::cin >> n >> l;
        aca.reset();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                std::cin >> da[i][j];
                da[i][j]--;
            }
            aca.insert(da[i], l, i);
        }

        aca.make_ac_automaton();


        int size = aca.size();
        init_matrix(size);
        gauss(size);

        std::cerr << a[0][size] << "\n";
        for (int i = 0; i < n; i++) {
            double x = a[inputid[i]][size];
            if (abs(x) <= eps) x = 0;
            if (i) std::cout << " ";
            std::cout << std::fixed << std::setprecision(6) << x;
        }
        std::cout << "\n";
    }
}

